
import 'dart:async';

import 'package:flutter_getx/core/utils/event_manage.dart';

import 'i_controller_delegate.dart';

class EventDelegate implements IControllerDelegate {

  List<StreamSubscription> subscriptionList = [];

  void addEvent<T>(void Function(T event)? onData, {Function? onError, void Function()? onDone, bool? cancelOnError}){
    subscriptionList.add(EventSingleton.eventBus.on<T>().listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError));
  }

  @override
  void onClose() {
    for (var subscription in subscriptionList) {
      subscription.cancel();
    }
  }

  @override
  void onInit() {

  }

  @override
  void onReady() {

  }

}